/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package ticketmaster.presentation.customer;

import ticketmaster.presentation.customer.purchase.SearchView;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
import java.awt.event.*;
import ticketmaster.dao.*;
import ticketmaster.dataobject.*;
import ticketmaster.presentation.BaseFrame;

public class CustomerHomeView extends CustomerBasePanel
{

    public CustomerHomeView()
    {
        //setSize(1000, 700);

//        Toolkit toolkit = Toolkit.getDefaultToolkit();
//        Dimension d = toolkit.getScreenSize();
//        this.setLocation((int) (d.getWidth() - this.getWidth()) / 2, (int) (d.getHeight() - this.getHeight()) / 2);

        jToolBar1 = new JToolBar(null, JToolBar.VERTICAL);
        btnBuy = new javax.swing.JButton();
        btnTickets = new javax.swing.JButton();
        btnAccount = new javax.swing.JButton();
        btnEdit = new javax.swing.JButton();
        pnlMain = new javax.swing.JPanel();
        lbTitle = new javax.swing.JLabel();
        pnlTitle = new javax.swing.JPanel();

        //setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
        setName("Form"); // NOI18N

        jToolBar1.setFloatable(false);
        jToolBar1.setRollover(true);
        jToolBar1.setFocusable(false);
        jToolBar1.setName("jToolBar1"); // NOI18N
        jToolBar1.setRequestFocusEnabled(false);

        org.jdesktop.application.ResourceMap resourceMap = org.jdesktop.application.Application.getInstance(ticketmaster.TicketMasterApp.class).getContext().getResourceMap(CustomerHomeView.class);
        btnBuy.setIcon(resourceMap.getIcon("btnBuy.icon")); // NOI18N
        btnBuy.setText(resourceMap.getString("btnBuy.text")); // NOI18N
        btnBuy.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnBuy.setMaximumSize(new java.awt.Dimension(159, 71));
        btnBuy.setMinimumSize(new java.awt.Dimension(159, 71));
        btnBuy.setName("btnBuy"); // NOI18N
        btnBuy.setPressedIcon(resourceMap.getIcon("btnBuy.pressedIcon")); // NOI18N
        btnBuy.setRolloverIcon(resourceMap.getIcon("btnBuy.rolloverIcon")); // NOI18N
        btnBuy.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnBuyActionPerformed(evt);
            }
        });
        jToolBar1.add(btnBuy);

        btnTickets.setIcon(resourceMap.getIcon("btnTickets.icon")); // NOI18N
        btnTickets.setText(resourceMap.getString("btnTickets.text")); // NOI18N
        btnTickets.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnTickets.setMaximumSize(new java.awt.Dimension(159, 71));
        btnTickets.setMinimumSize(new java.awt.Dimension(159, 71));
        btnTickets.setName("btnTickets"); // NOI18N
        btnTickets.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnTicketsActionPerformed(evt);
            }
        });
        jToolBar1.add(btnTickets);

        btnAccount.setIcon(resourceMap.getIcon("btnAccount.icon")); // NOI18N
        btnAccount.setText(resourceMap.getString("btnAccount.text")); // NOI18N
        btnAccount.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnAccount.setMaximumSize(new java.awt.Dimension(159, 71));
        btnAccount.setMinimumSize(new java.awt.Dimension(159, 71));
        btnAccount.setName("btnAccount"); // NOI18N
        btnAccount.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnAccountActionPerformed(evt);
            }
        });
        jToolBar1.add(btnAccount);

        btnEdit.setIcon(resourceMap.getIcon("btnEdit.icon")); // NOI18N
        btnEdit.setText(resourceMap.getString("btnEdit.text")); // NOI18N
        btnEdit.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        btnEdit.setMaximumSize(new java.awt.Dimension(159, 71));
        btnEdit.setMinimumSize(new java.awt.Dimension(159, 71));
        btnEdit.setName("btnEdit"); // NOI18N
        btnEdit.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                btnEditActionPerformed(evt);
            }
        });
        jToolBar1.add(btnEdit);

        pnlMain.setName("pnlMain");
        pnlTitle.setName("pnlTitle");
        
        lbTitle.setFont(resourceMap.getFont("lbTitle.font"));
        lbTitle.setText(resourceMap.getString("lbTitle.text"));
        lbTitle.setName("lbTitle");

        pnlTitle.add(lbTitle);

        // Creates a panel to hold all my components
        JPanel panel = new JPanel(new BorderLayout());
        panel.setLayout(new GridBagLayout());
        // give the panel a border gap of 5 pixels
        panel.setBorder(new EmptyBorder(new Insets(5, 5, 5, 5)));
        this.add(BorderLayout.CENTER, panel);

        GridBagConstraints c = new GridBagConstraints();

//        // Define preferred sizes for my entry fields
//        Dimension shortField = new Dimension(40, 20);
//        Dimension mediumField = new Dimension(120, 20);
//        Dimension longField = new Dimension(240, 20);
//        Dimension hugeField = new Dimension(240, 80);
//
//        // Spacing between the label and the field
//        EmptyBorder border = new EmptyBorder(new Insets(0, 0, 0, 10));
//        EmptyBorder border1 = new EmptyBorder(new Insets(0, 20, 0, 10));

        // add some space around all my components to avoid cluttering
        c.insets = new Insets(2, 2, 2, 2);

        // anchors all my components to the west
        c.anchor = GridBagConstraints.WEST;

//        c.gridx = 0;
//        c.weightx = 1.0; // use all available horizontal space
//        c.gridwidth = 2;
//        panel.add(pnlTitle, c);

        c.gridx = 0;
        c.weightx = 0.0; // do not use any available horizontal space
        c.gridwidth = 1; // spans across 1 columns
        c.fill = GridBagConstraints.HORIZONTAL;
        panel.add(jToolBar1, c);

        c.gridx = 1;
        c.weightx = 1.0; // use all available horizontal space
        c.weighty = 1.0; // use all available vertical space
        c.gridwidth = 2; // spans across 2 columns
        c.gridheight = 2; // spans across 2 rows
        c.fill = GridBagConstraints.BOTH; // fills up the cols & rows
        //c.fill = GridBagConstraints.HORIZONTAL;
        panel.add(pnlMain, c);
        

//        WindowListener wndCloser = new WindowAdapter()
//        {
//            @Override
//            public void windowClosing(WindowEvent e)
//            {
//                System.exit(0);
//            }
//        };
//        addWindowListener(wndCloser);

        setVisible(true);
    }

    public static void main(String[] args)
    {
        new CustomerHomeView();
    }

    private void btnEditActionPerformed(java.awt.event.ActionEvent evt)
    {
        CustomerProfileView CP = new CustomerProfileView();
        this.pnlMain.removeAll();
        this.pnlMain.add(CP);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        this.lbTitle.setText("Customer profile");
        CP.setPnlParent(pnlMain);
    }

    private void btnBuyActionPerformed(java.awt.event.ActionEvent evt)
    {
        SearchView sv = new SearchView();
        this.pnlMain.removeAll();
        this.pnlMain.add(sv);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        this.lbTitle.setText("Customer profile");
        sv.setPnlParent(pnlMain);

        //CustomerPurchaseView cpv = new CustomerPurchaseView();
//        SeatSelectionView ssv = new SeatSelectionView();
//        this.pnlMain.removeAll();
//        this.pnlMain.add(ssv);
//        this.pnlMain.validate();
//        this.pnlMain.repaint();
//        this.lbTitle.setText("Customer purchase");
//        ssv.setPnlParent(pnlMain);
    }

    private void btnTicketsActionPerformed(java.awt.event.ActionEvent evt)
    {
        CustomerTicketsView ctv = new CustomerTicketsView();
        this.pnlMain.removeAll();
        this.pnlMain.add(ctv);
        this.pnlMain.validate();
        this.pnlMain.repaint();
        this.lbTitle.setText("Customer Tickets");
        ctv.setPnlParent(pnlMain);
    }

    private void btnAccountActionPerformed(java.awt.event.ActionEvent evt)
    {
        CustomerAccountView cav;
        PremiumCustomerPanel pcv;
        int userID = getUser().getUserID();
        PremiumCustomer pc = new PremiumCustomer();
        pc.setCustomerID(userID);
        this.pnlMain.removeAll();
        if(DAOFactory.getInstance().getPremiumCustomerDAO().findPremiumCustomer(pc) != null)
        {
            pcv = new PremiumCustomerPanel();
            this.pnlMain.add(pcv);
            pcv.setPnlParent(pnlMain);
        }
        else
        {
            cav = new CustomerAccountView();
            this.pnlMain.add(cav);
            cav.setPnlParent(pnlMain);
        }
        this.pnlMain.validate();
        this.pnlMain.repaint();
        this.lbTitle.setText("Customer account");

    }

    private javax.swing.JButton btnAccount;
    private javax.swing.JButton btnBuy;
    private javax.swing.JButton btnEdit;
    private javax.swing.JButton btnTickets;
    private javax.swing.JToolBar jToolBar1;
    private javax.swing.JLabel lbTitle;
    private javax.swing.JPanel pnlMain;
    private javax.swing.JPanel pnlTitle;
}
